import { exportPayableShipmentExcelApi, generateAccountStatementApi } from "@/api/financialManagement/payableManagement";
import { message, Modal } from "ant-design-vue";
import { createVNode, Ref } from "vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
// import CommonHook from "@/hook/commonHook";
export default function OperationHook(state: {
  dialogOpts: Base.DialogOpts;
  drawerOpts: Base.DrawerOpts;
  emit: any;
  loading: Ref<boolean>;
  passData: Ref<StatementPayable.ListRows>;
  init: () => void;
}) {
  const { passData, loading, emit, drawerOpts, dialogOpts } = state;
  // const { downloadFileByBlob } = CommonHook();
  const generateAccountStatementHandle = () => {
    Modal.confirm({
      title: "正在进行生成对账单的操作，请再次确认!",
      icon: createVNode(ExclamationCircleOutlined),
      onOk() {
        loading.value = true;
        generateAccountStatementApi(passData.value.id)
          .then((res: any) => {
            const { code } = res;
            if (code === 200) {
              message.success("操作成功!");
              emit("submit");
            }
          })
          .finally(() => (loading.value = false));
      }
    });
  };
  // 导出
  const exportStatementHandle = () => {
    loading.value = true;
    return exportPayableShipmentExcelApi([passData.value.id])
      .then((res: any) => {
        const { code } = res;
        if (code === 200) {
          message.success("创建任务成功，请前往导出中心下载！");
        }
      })
      .finally(() => (loading.value = false));
  };
  //成本调整
  const ModifyAdjustCostHandle = (row: Base.GeneraDataType) => {
    dialogOpts.title = "成本调整";
    dialogOpts.width = "500px";
    dialogOpts.component = "ModifyAdjustCost";
    dialogOpts.passData = row;
    dialogOpts.visible = true;
  };

  //导入账单
  const ImportFeetHandle = (row: Base.GeneraDataType) => {
    dialogOpts.title = "导入账单";
    dialogOpts.width = "500px";
    dialogOpts.component = "ImportFee";
    dialogOpts.passData = row;
    dialogOpts.visible = true;
  };

  // 查看费用
  const showFeeHandle = (row: Base.GeneraDataType) => {
    drawerOpts.title = "查看费用";
    drawerOpts.width = "1200px";
    drawerOpts.component = "ShowFee";
    drawerOpts.type = 1;
    drawerOpts.passData = row;
    drawerOpts.visible = true;
  };
  const showProblemHandle = (row: Base.GeneraDataType) => {
    dialogOpts.title = "查看问题";
    dialogOpts.width = "720px";
    dialogOpts.component = "ShowIssue";
    dialogOpts.type = 1;
    dialogOpts.passData = row;
    dialogOpts.visible = true;
  };
  return {
    generateAccountStatementHandle,
    exportStatementHandle,
    showFeeHandle,
    showProblemHandle,
    ModifyAdjustCostHandle,
    ImportFeetHandle
  };
}
